package UserMangement;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import Loginout.UserBean;

@WebServlet("/roleDetermine")
public class roleDetermine extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		HttpSession session = req.getSession();
		UserBean UB = (UserBean) session.getAttribute("ub");

	
		if (UB == null) {

			resp.sendRedirect("error.html");

		} else
			try {
				if (UB.isAdmin())

				{
					session.setAttribute("ub", UB);	
					resp.sendRedirect("UserManage.jsp");
					
				} else if (UB.isStaff())
				{
					session.setAttribute("ub", UB);	
					resp.sendRedirect("ReaderManage.jsp");
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	
		
	}
